//字符串全部替换
String.prototype.replaceAll = function(s1,s2){ 
	return this.replace(new RegExp(s1,"gm"),s2); 
};

//格式化金额
function fmoney(s, n) {   
   n = n > 0 && n <= 20 ? n : 2;   
   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";   
   var l = s.split(".")[0].split("").reverse(),   
   r = s.split(".")[1];   
   t = "";   
   for(var i = 0; i < l.length; i ++ ) {   
      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");   
   }   
   return t.split("").reverse().join("") + "." + r;   
} 

function fkong(value) {
	return (value==null||value==undefined)?"":value;
}

//jqueryui dialog封装
jQuery.extend(jQuery, {   
    // jQuery UI alert弹出提示   
    jqalert: function(text, title, fn) {   
        var html =   
        '<div class="dialog" id="dialog-message">' +   
        ' <p>' +  text +  
       // ' <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 0 0;"></span>' + text +   
        ' </p>' +   
        '</div>';   
        return $(html).dialog({   
            //autoOpen: false,   
            resizable: false,   
            modal: true,   
            show: {   
                effect: 'fade',   
                duration: 300   
            },   
            title: title || "提示信息",   
            buttons: {   
                "确定": function() {   
                var dlg = $(this).dialog("close");   
                fn && fn.call(dlg);   
            }   
            }   
        });   
    },   
    // jQuery UI alert弹出提示,一定间隔之后自动关闭   
    jqtimeralert: function(text, title, fn, timerMax) {   
        var dd = $(   
        '<div class="dialog" id="dialog-message">' +   
        ' <p>' +   
        ' <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 0 0;"></span>' + text +   
        ' </p>' +   
        '</div>');   
        dd[0].timerMax = timerMax || 3;   
        return dd.dialog({   
            //autoOpen: false,   
            resizable: false,   
            modal: true,   
            show: {   
            effect: 'fade',   
            duration: 300   
        },   
        open: function(e, ui) {   
            var me = this,   
            dlg = $(this),   
            btn = dlg.parent().find(".ui-button-text").text("确定(" + me.timerMax + ")");   
            --me.timerMax;   
            me.timer = window.setInterval(function() {   
                btn.text("确定(" + me.timerMax + ")");   
                if (me.timerMax-- <= 0) {   
                    dlg.dialog("close");   
                    fn && fn.call(dlg);   
                    window.clearInterval(me.timer); // 时间到了清除计时器   
                }   
            }, 1000);   
        },   
        title: title || "提示信息",   
        buttons: {   
            "确定": function() {   
                    var dlg = $(this).dialog("close");   
                    fn && fn.call(dlg);   
                    window.clearInterval(this.timer); // 清除计时器   
                }   
            },   
            close: function() {   
                    window.clearInterval(this.timer); // 清除计时器   
            }   
        });   
    },   
    // jQuery UI confirm弹出确认提示   
    jqconfirm: function(text, title, fn1, fn2) {   
        var html =   
        '<div class="dialog" id="dialog-confirm">' +   
        ' <p>' +   
        ' <span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>' + text +   
        ' </p>' +   
        '</div>';   
        return $(html).dialog({   
            //autoOpen: false,   
            resizable: false,   
            modal: true,   
            show: {   
                effect: 'fade',   
                duration: 300   
            },   
            title: title || "提示信息",   
            buttons: {   
                "确定": function() {   
                    var dlg = $(this).dialog("close");   
                    fn1 && fn1.call(dlg, true);   
                },   
                "取消": function() {   
                    var dlg = $(this).dialog("close");   
                    fn2 && fn2(dlg, false);   
                }   
            }   
        });   
    },   
    // jQuery UI 弹出iframe窗口   
    jqopen: function(url, options) {   
        var html =   
        '<div class="dialog" id="dialog-window" title="提示信息">' +   
        ' <iframe src="' + url + '" frameBorder="0" style="border: 0; " scrolling="auto" width="100%" height="100%"></iframe>' +   
        '</div>';   
        return $(html).dialog($.extend({   
            modal: true,   
            closeOnEscape: false,   
            draggable: false,   
            resizable: false,   
            close: function(event, ui) {   
                $(this).dialog("destroy"); // 关闭时销毁   
            }   
        }, options));   
    },   
    // jQuery UI confirm提示   
    confirm: function(evt, text, title) {   
        evt = $.event.fix(evt);   
        var me = evt.target;   
        if (me.confirmResult) {   
            me.confirmResult = false;   
            return true;   
        }   
        jQuery.jqconfirm(text, title, function(e) {   
            me.confirmResult = true;   
            if (e) {   
                if (me.href && $.trim(me.href).indexOf("javascript:") == 0) {   
                    $.globalEval(me.href);   
                    me.confirmResult = false;   
                    return;   
                }   
                var t = me.type && me.type.toLowerCase();   
                if (t && me.name && (t == "image" || t == "submit" || t == "button")) {   
                    __doPostBack(me.name, "");   
                    me.confirmResult = false;   
                    return;   
                }   
                if (me.click) me.click(evt);   
            }   
            return false;   
        });   
        return false;   
    }   
}); 


//加法   
Number.prototype.add = function(arg){   
    var r1,r2,m;   
    try{r1=this.toString().split(".")[1].length}catch(e){r1=0}   
    try{r2=arg.toString().split(".")[1].length}catch(e){r2=0}   
    m=Math.pow(10,Math.max(r1,r2))   
    return (this*m+arg*m)/m   
}   
 
//减法   
Number.prototype.sub = function (arg){   
    return this.add(-arg);   
}   
 
//乘法   
Number.prototype.mul = function (arg)   
{   
    var m=0,s1=this.toString(),s2=arg.toString();   
    try{m+=s1.split(".")[1].length}catch(e){}   
    try{m+=s2.split(".")[1].length}catch(e){}   
    return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)   
}   
 
//除法   
Number.prototype.div = function (arg){   
    var t1=0,t2=0,r1,r2;   
    try{t1=this.toString().split(".")[1].length}catch(e){}   
    try{t2=arg.toString().split(".")[1].length}catch(e){}   
    with(Math){   
        r1=Number(this.toString().replace(".",""))   
        r2=Number(arg.toString().replace(".",""))   
        return (r1/r2)*pow(10,t2-t1);   
    }   
} 


$(function() {
	init(document.title);
});


function init(title) {
	if(title!='登陆'&&title!='目录') {
		var html = "<div class='header'>"+
				"<div class='top_header'>"+
			        "<h1>"+
			        	"<div style='float:right;'>当前用户："+currentUser+"</div>"+
			            "<a href='"+basePath+"/login/index.htm' class='go_home'>返回主页</a>"+title+
			        "</h1>"+
			        
				"</div>"+
			"</div>";
		$("body").prepend(html);
	}
	
}
